package Demo.Interfaces;

import java.util.Arrays;

/**
 * @className: Demo2
 * @author: 芃
 * @description: 测试常用接口-Comparator接口和Comparable接口（推荐使用Comparator接口，对类的侵入性比较弱）
 * @date: 2023/8/17 12:10
 */
public class Demo2 {

    public static void main(String[] args) {
        Student2[] students = new Student2[5];
        students[0] = new Student2("张三",21,85.5);
        students[1] = new Student2("李四",23,97.4);
        students[2]= new Student2("王麻子",24,77.6);
        students[3]= new Student2("赵六",19,88.9);
        students[4] = new Student2("陈七",26,93.4);
        System.out.println("排序前:");
        System.out.println(Arrays.toString(students));

        ScoreComparator scoreComparator = new ScoreComparator();
        Arrays.sort(students,scoreComparator);
        System.out.println("排序后:");
        System.out.println(Arrays.toString(students));

        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(students,ageComparator);
        System.out.println("排序后:");
        System.out.println(Arrays.toString(students));
    }

    public static void main1(String[] args) {
        Student[] students = new Student[5];
        students[0] = new Student("张三",21,85.5);
        students[1] = new Student("李四",23,97.4);
        students[2]= new Student("王麻子",24,77.6);
        students[3]= new Student("赵六",19,88.9);
        students[4] = new Student("陈七",26,93.4);

        System.out.println(students[0].compareTo(students[1]));
        System.out.println("排序前:");
        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println("排序后:");
        System.out.println(Arrays.toString(students));
    }
}
